<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Kernel\Http;

use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;

class Response
{
    protected ResponseInterface $response;

    public function __construct(ContainerInterface $container)
    {
        $this->response = $container->get(ResponseInterface::class);
    }

    public function success(mixed $data = [])
    {
        return $this->response->json([
            'code' => 1,
            'data' => $data,
        ]);
    }

    public function fail(int $code, string $msg = '')
    {
        return $this->response->json([
            'code' => $code,
            'msg' => $msg,
        ]);
    }

    public function redirect($url, int $status = 302)
    {
        return $this->response->redirect($url, $status);
    }
}
